package com.diliuzun.delivery.service;

import com.diliuzun.delivery.entity.Book;
import com.diliuzun.delivery.mapper.BookMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.ArrayList;

@Service
@Transactional
public class BookService {
    @Autowired
    private BookMapper bookMapper;

    public int addBook(Book book){
        book.setState("1");
        if("".equals(book.getDate())){
            book.setDate(null);
        }
        if("".equals(book.getPrice())){
            book.setPrice(null);
        }
        int count = bookMapper.addBook(book);
        return count;
    }

    public int updateBook(Book book){
        return bookMapper.updateBook(book);
    }

    public int deleteBookById(Serializable id){
        return bookMapper.deleteBookById(id);
    }

    public Book selectBookById(Serializable id){
        return bookMapper.selectBookById(id);
    }

    public ArrayList<Book> selectBooks(Book book){
        return bookMapper.selectBooks(book);
    }
}
